package seiacpjava_a2.datastructures.linkedlist;

import static org.junit.Assert.*;

import org.junit.Test;

public class LinkedListTestCase {

	@Test
	public void testAdd() {
		
		int item1 = 1;
		int item2 = 2;
		int item3 = 3;
		
		LinkedList list = new LinkedList();		
		assertEquals(0, list.getLength());
		
		list.add(item1);
		assertEquals(1, list.getLength());
		
		ListNode firstNode = list.getFirst();
		ListNode lastNode = list.getLast();
		
		assertEquals(1, firstNode.getItem());
		assertEquals(1, lastNode.getItem());
		
		list.add(item2);
		assertEquals(2, list.getLength());
		
		ListNode firstNode2 = list.getFirst();
		ListNode lastNode2 = list.getLast();
		
		assertEquals(1, firstNode2.getItem());
		assertEquals(2, lastNode2.getItem());
		
		
		list.add(item3);
		assertEquals(3, list.getLength());
		
		ListNode firstNode3 = list.getFirst();
		ListNode lastNode3 = list.getLast();
		
		assertEquals(1, firstNode3.getItem());
		assertEquals(3, lastNode3.getItem());
		
		
		
	}
	
	
	@Test
	public void testContains(){
		
		
		 int item1 = 1;
		 int item2 = 2;
		 int item3 = 3;
		 
		 LinkedList list = new LinkedList();
		 assertEquals(0, list.getLength());
			
	     list.add(item1);
		 assertEquals(1, list.getLength());
		 
		 list.add(item2);
		 assertEquals(2, list.getLength());
		 
		 list.add(item3);
		 assertEquals(3, list.getLength());
		 
		 assertTrue(list.contains(item1));
		 assertEquals(1,list.getNumberOfAccesses());
		 
		 assertTrue(list.contains(item2));
		 assertEquals(2,list.getNumberOfAccesses());
		 
		 assertTrue(list.contains(item3));
		 assertEquals(3,list.getNumberOfAccesses());
		 
		 assertFalse(list.contains(4));
		 assertEquals(3,list.getNumberOfAccesses());
	}
	
	@Test
	public  void testContainsWithEmptyList()
	{
		
		LinkedList list = new LinkedList();
		
		assertEquals(0, list.getLength());
		assertFalse(list.contains(1));
	
		
	}
	
	
	
	@Test 
	public void testGetItemAt(){
		int item0 = 0;
		 int item1 = 1;
		 int item2 = 2;
		 
		 LinkedList list = new LinkedList();
		 assertEquals(0, list.getLength());
			
	     list.add(item0);
		 assertEquals(1, list.getLength());
		 
		 list.add(item1);
		 assertEquals(2, list.getLength());
		 
		 list.add(item2);
		 assertEquals(3, list.getLength());
		 
		 assertEquals(item0,list.getItemAt(0));
		 assertEquals(item1,list.getItemAt(1));
		 assertEquals(item2,list.getItemAt(2));
	}
	

}
